package webapp.mvc.models;

import com.zoowii.jpa_utils.extension.ExtendFinder;
import com.zoowii.jpa_utils.orm.Model;
import webapp.mvc.enums.IntBooleans;
import webapp.mvc.utils.IdGenerator;
import webapp.mvc.utils.TimeUtil;

import javax.persistence.*;
import java.sql.Timestamp;

@Entity
@Table(name = "comment")
public class CommentEntity extends Model {
    public static final ExtendFinder<String, CommentEntity> find = new ExtendFinder<String, CommentEntity>(String.class, CommentEntity.class);
    private String id = IdGenerator.nextId();
    private String title;
    private String userId;
    private String content;
    private String shopId;
    private String productId;
    private int deleted = IntBooleans.FALSE;
    private Timestamp createTime = TimeUtil.currentTimestamp();
    private Timestamp modifyTime = TimeUtil.currentTimestamp();

    @Id
    @Column(name = "id", nullable = false)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "title", nullable = false)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "user_id", nullable = false)
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Column(name = "content", nullable = false)
    @Lob
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column(name = "shop_id", nullable = false)
    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    @Column(name = "product_id", nullable = false)
    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    @Column(name = "deleted", nullable = false)
    public int getDeleted() {
        return deleted;
    }

    public void setDeleted(int deleted) {
        this.deleted = deleted;
    }

    @Column(name = "create_time", nullable = false)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Column(name = "modify_time", nullable = false)
    public Timestamp getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Timestamp modifyTime) {
        this.modifyTime = modifyTime;
    }

    @Transient
    public int getRating() {
        return 5;
    }
}
